package com.ziq.baselib.test.drawable

import android.annotation.SuppressLint
import android.graphics.Color
import android.os.Bundle
import android.widget.Toast
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.drawable.DrawableCompat
import com.ziq.base.base.BaseActivity
import com.ziq.base.view.drawable.colorStateListBuild
import com.ziq.base.view.drawable.gradientDrawableBuild
import com.ziq.base.view.drawable.stateListDrawableBuild
import com.ziq.base.extension.binding
import com.ziq.base.extension.click
import com.ziq.base.extension.dp
import com.ziq.baselib.R
import com.ziq.baselib.databinding.ActivityTestDrawableBinding


class DrawableActivity: BaseActivity() {

    private val binding : ActivityTestDrawableBinding by binding()

    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding.root
        //size 有效果
        binding.iv1.setImageResource(R.drawable.drawable_test_1)
        //size 无效果
//        binding.iv1.background = ResourcesCompat.getDrawable(resources, R.drawable.drawable_test_1, null)

        binding.iv2.click {
            binding.iv2.background = gradientDrawableBuild {
                solidColor = Color.BLUE
            }
            Toast.makeText(this, "test", 3000).show()
        }

        binding.tv3.setTextColor(colorStateListBuild {
            colorItem {
                color = Color.RED
            }
            colorItem {
                color = Color.BLUE
                state = intArrayOf(android.R.attr.state_selected)
            }
        })
        binding.tv3.click {
            binding.tv3.isSelected = !binding.tv3.isSelected
        }

        binding.iv4.background = stateListDrawableBuild {
            drawableItem {
                drawable = gradientDrawableBuild {
                    solidColor = Color.BLUE
                    cornerRadius = 10.dp.toFloat()
                }
                state = intArrayOf(android.R.attr.state_selected)
            }
            drawableItem {
                drawable = ResourcesCompat.getDrawable(resources, R.drawable.ic_launcher_foreground, null)
            }
        }
        binding.iv4.click {
            binding.iv4.isSelected = !binding.iv4.isSelected
        }
    }
}